import 'package:flutter/material.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/setting/children/address/add_address/add_address_page.dart';
import 'package:flutterproject/page/setting/children/address/controller/address_controller.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/extension/widget_extension.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/button_common.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';

class AddressPage extends BaseState<AddressController> {
  @override
  AddressController initController() => AddressController();

  @override
  Widget initView(BuildContext context) {
    return Container(
      width: Get.width,
      height: Get.height,
      color: Color(0xFFF6F6F6),
      child: Column(
        children: [
          AppBarCommon(title: "地址管理"),
          Expanded(
            child: Container(
              margin: MarginPaddingUtil.symmetric(vertical: 23, horizontal: 20),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(20.sp),
              ),
              child: ListView.separated(
                shrinkWrap: true,
                separatorBuilder: (context, index) => Padding(
                  padding: MarginPaddingUtil.symmetric(horizontal: 37),
                  child: Divider(
                    color: Color(0xFFE7E7E7),
                  ),
                ),
                itemCount: controller.addressList?.length ?? 0,
                itemBuilder: (context, index) {
                  final tempBean = controller.addressList![index];
                  return Row(
                    children: [
                      37.widthBox,
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          TextCommon(
                            tempBean.base ?? "",
                            size: 24.sp,
                            color: Color(0xFF707070),
                            lineHeight: 35.sp,
                          ),
                          TextCommon(
                            tempBean.detail ?? "",
                            size: 28.sp,
                            fontWeight: FontWeight.bold,
                            lineHeight: 40.sp,
                          ),
                          Row(
                            children: [
                              TextCommon(
                                tempBean.name ?? "",
                                size: 24.sp,
                                lineHeight: 35.sp,
                                color: Color(0xFF707070),
                              ),
                              25.widthBox,
                              TextCommon(
                                tempBean.tel ?? "",
                                size: 24.sp,
                                color: Color(0xFF707070),
                                lineHeight: 35.sp,
                              ),
                            ],
                          )
                        ],
                      ),
                      Spacer(),
                      ImageCommon("/icon/edit", size: 20.sp)
                          .addClickEvent(() async {
                        await Get.to(AddAddressPage(),
                            arguments: controller.addressList![index]);
                        controller.getAddressData();
                      }),
                      37.widthBox,
                    ],
                  ).addClickEvent(() async {
                    if (Get.arguments) {
                      Get.back(result: tempBean);
                    }
                  });
                },
              ),
            ),
          ),
          Container(
            width: Get.width,
            color: Colors.white,
            padding: MarginPaddingUtil.symmetric(vertical: 22, horizontal: 200),
            child: ButtonCommon(
              text: "新增地址",
              onTap: () async {
                await Get.to(AddAddressPage());
                controller.getAddressData();
              },
              fontSize: 32.sp,
              fontColor: Colors.white,
              color: Color(0xFFEDC88B),
              borderRadios: 50,
              padding: MarginPaddingUtil.only(top: 25, bottom: 29),
            ),
          )
        ],
      ),
    );
  }
}
